<?php 
    require '../db.func.php';
    require '../tools.func.php';
    require  'auth.php';
	require 'head.php';
	$id=intval($_GET['id']);

	$prefix=getprefix();
	$sql="SELECT id,username,name,age,email,phone FROM  {$prefix}user  WHERE id='{$id}' ";
	$res=queryone($sql);

	
	if(!empty($_POST['name'])){
		$name=$_POST['name'];
		$age=$_POST['age'];
		$email=$_POST['email'];
		$phone=$_POST['phone'];
		
		$sq="UPDATE {$prefix}user SET  name='$name', age='$age',email='$email',phone='$phone' WHERE id='{$id}'";
		execute($sq)  ;
		$res=array_merge($res,$_POST);
		queryone($sql);
		//在查询一次

		// aaray_merge  把两个数组合成一起   后面的元素覆盖前面的元素
		setinfo('更新成功');

		
	  }
	
	
?>
				<div class="row">
					<div class="col-md-12">
						<div class="card">
							<div class="card-header card-header-primary">
								<h4 class="card-title">添加用户</h4>
								<p class="card-category">添加一个用户</p>
							</div>
							<div class="card-body">
								<?php if(hasinfo()) echo getinfo();?>
								<form  action="useredit.php?id=<?php echo $id?>" method="POST">
									
									<div class="row">
										<div class="col-md-12">
											<div class="form-group">
												<label class="bmd-label-floating">用户名</label>
												<input type="text"  disabled class="form-control"  name="username" value="<?php echo $res['username']?>">
												
											</div>
										</div>
									</div>
									<div class="row">
										<div class="col-md-6">
											<div class="form-group">
												<label class="bmd-label-floating">姓名</label>
												<input type="text" value="<?php echo $res['name']?>" class="form-control" name="name" >
											</div>
										</div>
										<div class="col-md-6">
											<div class="form-group">
												<label class="bmd-label-floating">年龄</label>
												<input type="number" value="<?php echo $res['age']?>" class="form-control" name="age">
											</div>
										</div>
									</div>
									<div class="row">
										<div class="col-md-12">
											<div class="form-group">
												<label class="bmd-label-floating">联系电话</label>
												<input type="text" name="phone" class="form-control" name="phone" value="<?php echo $res['phone']?>" >
											</div>
										</div>
									</div>
									<div class="row">
										<div class="col-md-12">
											<div class="form-group">
												<label class="bmd-label-floating">电子邮箱</label>
												<input type="email" name="email" class="form-control"
												name="email" value="<?php echo $res['email']?>">
											</div>
											
										</div>
						
									</div>
									<button type="submit" class="btn btn-primary pull-right">更新信息</button>
									<div class="clearfix"></div>
								</form>
							</div>
						</div>
					</div>

				</div>
<?php
	require 'foot.php';
?>